
package combat.dudes.client.gui;

import java.awt.Graphics;
import java.awt.Toolkit;

import javax.swing.JPanel;

import combat.dudes.client.ClientApp;
import combat.dudes.client.gui.threads.ClientThread;
import combat.dudes.client.gui.threads.ClientThread.ClientThreadType;


/**
 * @author Laurens Andriessen
 * @version 1.0
 */
public class ClientGUI {

	// Global variables for GUI threads
	// Main window ('desktop') title
	public static String guiShellTitle = "CAMS|Force Vision - D.U.D.E.S. CMS - Prototype v1.0, projectgroup 2";

	// Shell width and height
	public static final int guiShellWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
	public static final int guiShellHeight = Toolkit.getDefaultToolkit().getScreenSize().height;

	private static int zoom = 1;
	public synchronized static int getZoom() {
		return zoom;
	}
	public synchronized static void setZoom(int z) {
		if(z < 1)
			zoom = 1;
		else if(z > 4)
			zoom = 4;
		else zoom = z;
	}


	// Shared JPanels which are 'filled' within the threads and 'shown' in the GUI_SHELL thread
	public static JPanel panelMainMap = new JPanel(null);
	public static JPanel panelMiniMap = new JPanel(null);
	public static JPanel panelInfo = new JPanel(null) {
		private static final long serialVersionUID = 1L;
		@Override
		public void paintComponent(Graphics g) {
			g.setColor(ClientGUITheme.guiPanelBg.darker());
			g.fillRect(0, 0, getWidth(), getHeight());
		}
	};
	public static JPanel panelMyStatus = new JPanel(null) {
		private static final long serialVersionUID = 1L;
		@Override
		public void paintComponent(Graphics g) {
			g.setColor(ClientGUITheme.guiPanelBg.darker());
			g.fillRect(0, 0, getWidth(), getHeight());
		}
	};
	public static JPanel panelChat = new JPanel(null) {
		private static final long serialVersionUID = 1L;
		@Override
		public void paintComponent(Graphics g) {
			g.setColor(ClientGUITheme.guiPanelBg.darker());
			g.fillRect(0, 0, getWidth(), getHeight());
		}
	};
	public static JPanel[] gui_panels = {
			panelMainMap, panelMiniMap, panelInfo, panelMyStatus, panelChat
	};


	public static ClientThread gui_shell = new ClientThread(ClientThreadType.GUI_SHELL);
	public static ClientThread gui_shell_repaint; // For the GUIShellMenu > Themes option, but it doesn't work (yet)
	public static ClientThread gui_mainmap = new ClientThread(ClientThreadType.GUI_MAINMAP);
	public static ClientThread gui_minimap = new ClientThread(ClientThreadType.GUI_MINIMAP);
	public static ClientThread gui_info = new ClientThread(ClientThreadType.GUI_INFO);
	public static ClientThread gui_mystatus = new ClientThread(ClientThreadType.GUI_MYSTATUS);
	public static ClientThread clock = new ClientThread(ClientThreadType.CLOCK);
	public static ClientThread gui_chat = new ClientThread(ClientThreadType.GUI_CHAT);
	public static ClientThread[] gui_threads = {
			gui_shell, gui_mainmap, gui_minimap, gui_info, gui_mystatus, clock, gui_chat
	};
	public static ClientThread[] gui_threads_waiting = {
			gui_mainmap, gui_minimap, gui_info, gui_mystatus, gui_chat
	};


	public ClientGUI() {

		try {
			gui_shell.setPriority(Thread.MAX_PRIORITY);
			for(ClientThread thread : gui_threads)
				thread.start();
		} catch(Exception e) {
			ClientApp.onError("A GUI-thread could not be started.", e, true);
		}

		try {
			for(ClientThread thread : gui_threads)
				thread.join();
		} catch(Exception e) {
			ClientApp.onError("A GUI-thread couldn't be joined.", e, true);
		}

	}
}
